#include<iostream>

using namespace std;
int ncases;
int n;
int a, b, c;

int main() {
   cin >> ncases;
   int sum = 0;
   for(int i=0; i<ncases; i++) {
      cin >> n;
      for(int j=0; j<n; j++) {
         cin >> a >> b >> c;
         sum += a*c;
      }
      cout << sum << endl;
      sum = 0;
   }
   return 0;
}
